﻿var loginPostUrl = "/admin/login/login";
var mainIndexUrl = "/admin/main/index";
$(document).ready(function () {
    $("#btn-login").click(function () {
        if ($('#login-form').form('validate')) {
            $.ajax({
                url: loginPostUrl,
                type: 'Post',
                data: $('#login-form').serialize(),
                dataType: 'json',
                timeout: 1000,
                success: function (data) {
                    if (data.state)
                        location.href = mainIndexUrl;
                    else {
                        msgShow("登入提示", data.message, data.state ? "info" : "error", function () {
                            if (data.state)
                                location.href = mainIndexUrl;
                            $('#imgCode').attr('src', $('#imgCode').attr('src') + '?');
                        });
                    }


                }
            });
        }
    });
    $('input').keydown(function (e) {
        if (e.ctrlKey && e.which == 13 || e.which == 13) {
            if ($('#login-form').form('validate')) {
                $.ajax({
                    url: loginPostUrl,
                    type: 'Post',
                    data: $('#login-form').serialize(),
                    dataType: 'json',
                    timeout: 1000,
                    success: function (data) {
                        if (data.state)
                            location.href = mainIndexUrl;
                        else {
                            msgShow("登入提示", data.message, data.state ? "info" : "error", function () {
                                if (data.state)
                                    location.href = mainIndexUrl;
                                $('#imgCode').attr('src', $('#imgCode').attr('src') + '?');
                            });
                        }
                    }
                });
            }
        }
    });
});